if(!dojo._hasResource["market.widgets.component.Content"]){
dojo._hasResource["market.widgets.component.Content"]=true;
dojo.provide("market.widgets.component.Content");
require(["dojo/_base/declare","dijit/_Widget","dojo/query","dojo/dom","dojo/dom-construct","dojo/_base/array"],function(declare,_widget,query,dom,contruct,array){
declare("market.widgets.component.Content",[_widget],{
_tmpl:'<div class="c_b_b c_c_b"><a href="../auth?view={participant.id}"><img src="getContent/{avatarGUID}/small" class="c_c_a"/></a><a href="../auth?view={participant.id}" class="h3"><h3><span>{name}</span></h3></a>&nbsp;<div>{pictures}</div><div class="c_c_n">{content}</div></div><div class="clear"></div>',
_likeTmpl:'<div class="c_c_c"><a href="#"><input type="hidden" value="likeIt"> '+globalLikeIt+' </a> |<a href="#"><input type="hidden" value="comment"><input type="hidden" value="{guid}"><input type="hidden" value="{totalComments}"><input type="hidden" value="down"> '+globalComments+' ({totalComments}) </a></div><div class="clear"></div><div name="contentComment">{latestComment}</div>',
_picTmpl:'<img src="getContent/{guid}/medium" class="box_picture2 border_thin"/>',
_comTmpl:'<div class="c_b_b_c_last"><div class="c_c_b_c"><img class="c_c_a_c" src="getContent/{avatarGUID}/small"><div class="c_c_n"><span class="nickName">{name}</span> - {content}</div></div><div class="clear"></div></div>',
_putComTmpl:'<div class="c_b_b_c"><div class="c_b_b_c_f"><input type="hidden" value="{id}"/>'+globalAddCommment+'</div></div><div class="clear"></div>',
_currentPost:null,_divNews:null,_divPictures:null,_divPost:null,_cDivPost:null,_cPostSym:null,_divFilesPost:null,target:null,
showPrivateNews:function(){
   var args = {ajaxUrl:'news/private',contentId:this._targetNode(),callback:function(data){
      SYSTEMWIDGET.content()._parseNews(data);
   }};
   SYSTEMWIDGET.ajaxWidget(args).callXhrGetJson();
},
showInboxNews:function(){
   var args = {ajaxUrl:'news/common',contentId:this._targetNode(),callback:function(data){
      SYSTEMWIDGET.content()._parseNews(data);
   }};
   SYSTEMWIDGET.ajaxWidget(args).callXhrGetJson();
},
_createPostDiv:function(){
   var posts=query('> div[name="_postDiv"]',this._targetNode());
   if (posts.length==0){
      this._divPictures=contruct.create('div',null,this._targetNode(),'first');
      this._divPost=contruct.create('div',{'name':'_postDiv','innerHTML':'<div class="c_p_b_b"><div class="c_b_b_c_f">'+globalTooltipAddnew+'</div></div><div class="clear"></div>'},this._targetNode(),'first');
      this._postEvents(this._divPost);
   }
},
_targetNode:function(){
   if (this.target==null) this.target=dojo.byId('center_content');
   return this.target;
},
_insertLatest:function(strNew,guid,contentFiles){
   this._currentPost.setValue('');
   var pictureHtmlTemp='';
   var _w=this;
   array.forEach(contentFiles,function(file,i){
      pictureHtmlTemp+=dojo.replace(_w._picTmpl,{guid:file.guid});
   });
   var content={guid:guid,totalComments:0,comments:[],content:strNew,name:getCurrentName(),avatarGUID:getContentGUID(participant.avatarGUID),pictures:pictureHtmlTemp};
   content.latestComment=this._latestComment(content.comments,content.id);
   var tmpl='<div class="lineNews"></div>'+this._tmpl+this._likeTmpl;
   var divNews=contruct.create('div',{innerHTML:dojo.replace(tmpl,content)},this._divNews,'first');
   this._divPictures.innerHTML='';
   this._newEvents(divNews);
},
_latestComment:function(comments,newsID){
   var commentHtml='';
   if (comments.length>0){
      var latest=comments[0];
      var partcp=latest.participant;
      if (partcp!=null){
      var commentObj={content:latest.content,name:getPartViewName(partcp),avatarGUID:getPartGUID(partcp)};
      commentHtml=dojo.replace(this._comTmpl,commentObj);
      }
   }
   commentHtml+=dojo.replace(this._putComTmpl,{id:newsID});;
   return commentHtml;
},
_parseNews:function(news){
   var _w=this;
   this._targetNode().innerHTML='';
   this._createPostDiv();
   this._divNews=contruct.create("div");
   contruct.place(this._divNews,this._divPost,'after');
   contruct.create('div',{'class':'lineNews'},this._divNews,'last');
   for(var index=0;index<news.length;index++){
      var content=news[index];
      var partcp=content.participant;
      content.name=getViewName(partcp.firstName,partcp.lastName,partcp.nickname);
      content.avatarGUID=getContentGUID(partcp.avatar.contentFile.guid);
      var pictureHtml='';
      array.forEach(content.contentFiles,function(file,i){
         pictureHtml+=dojo.replace(_w._picTmpl,file);
      });
      content.pictures=pictureHtml;
      content.latestComment=this._latestComment(content.comments,content.id);
      var tmpl='<div class="lineNews"></div>'+this._tmpl+this._likeTmpl;
      var divNews=contruct.create('div',{innerHTML:dojo.replace(tmpl,content)},this._divNews,'last');
      this._newEvents(divNews);
   }
},
_postEvents:function(divPostNews){
   var w=this;
   query('div.c_b_b_c_f',divPostNews).onclick(function(){
      if (w._cDivPost!=null){
         contruct.destroy(w._cDivPost);
      }
      w._cDivPost=contruct.create('div',null,this.parentNode,'last');
      w._currentPost=SYSTEMWIDGET.contentEditor({targetNode:w._cDivPost,editId:'postContent',handelEvents:w._editorEvents(),hasEdit:true,hasAttach:true,ignoreEdit:true},true);
      w._currentPost.showEditor();
      w._cPostSym=this;
      this.style.display='none';
   });
},
_newEvents:function(divNews){
   query('div.c_c_c > a',divNews).onclick(function(){
      var values = query('input[type="hidden"]', this); 
      var value=values[0].value;
      switch(value){
      case 'likeIt':
         break;
      case 'comment':
         var newsGUID=values[1].value;
         var totalComments=values[2].value;
         var status=values[3].value;
         if (totalComments>1){
            if (status=='down') SYSTEMWIDGET.comment({viewParent:this.parentNode.parentNode}).display(newsGUID); 
            else SYSTEMWIDGET.comment({viewParent:this.parentNode.parentNode}).hidden();
         }
         break;
      }
   });
   query('div[name="contentComment"] div.c_b_b_c_f',divNews).onclick(function(){
      var newsId=query('input[type="hidden"]',this)[0].value;
      SYSTEMWIDGET.comment({divIcon:this,parentNode:this.parentNode,commentNode:this.parentNode.parentNode,newsId:newsId}).show();
   });
},
_editorEvents:function(){
   var widget=this;
   var clickEvents = {
      saveClick:function(data){
         var _contentNews=data;
         var objectToQuery={'content':data};
         var index=0;
         array.forEach(widget._currentPost._selectedFiles,function(file,i){
            var state=file.state;
            if(null==state||'new'==state){
               objectToQuery['contentFiles['+index+'].guid']=file.guid;
               index++;
            }
         });
         var args={ajaxUrl:'saveContent/new',postData:dojo.objectToQuery(objectToQuery),callback:function(data){
            widget._triggerVisibleDivNews(false);
            widget._insertLatest(_contentNews,data.guid,widget._currentPost._selectedFiles);
            widget._currentPost._selectedFiles=[];
            widget._divFilesPost=null;
         }};
         SYSTEMWIDGET.ajaxWidget(args).callXhrPostJSON();
      },
      attachClick:function(){
         widget._handleAttached();
      },
      cancelClick:function(){
         widget._resetContent();
      }
   };
   return clickEvents;
},
_triggerVisibleDivNews:function(value){
   if (value){
      this._divNews.style.display='none';
      this._divPictures.style.display='';
   }else{
      this._divNews.style.display='';
      this._cDivPost.style.display='none';
      this._cPostSym.style.display='';
      this._divPictures.style.display='none';
   }
},
_handleAttached:function(){
   var widget=this;
   var album = SYSTEMWIDGET.album({targetNode:this._divPictures}); 
   album.showAlbums();
   album.handleAttached(function(){widget._addFiles();});
   this._triggerVisibleDivNews(true);
},
_resetContent:function(){
   this._currentPost._selectedFiles=[];
   this._parseFilesHTML();
   this._triggerVisibleDivNews(false);
   this._divFilesPost=null;
},
_addFiles:function(){
   this._currentPost.addFiles();
   this._parseFilesHTML();
   this._initFileEvent();
},
_removeFiles:function(removeGUID){
   this._currentPost.removeFile(removeGUID);
   this._parseFilesHTML();
   this._initFileEvent();
},
_parseFilesHTML:function(){
   var htmlFiles='';
   array.forEach(this._currentPost._selectedFiles,function(file,index){
      if (file.state!='delete'){
         htmlFiles+='<div class="box_float_left"><img src="getContent/'+file.guid+'" class="box_picture1 border_thin"/>';
         htmlFiles+='<div class="removeFile" style="display:none"><input type="hidden" value="'+file.guid+'"/></div></div>';
      }
   });
   if (htmlFiles!=''){
      htmlFiles+='<div class="clear"></div>';
   }
   if (this._divFilesPost==null)
      this._divFilesPost=contruct.create("div",null,this._divPost,'last');
   this._divFilesPost.innerHTML=htmlFiles;
},
_initFileEvent:function(){
   var widget=this;
   query("> div", this._divFilesPost).onmouseover(function(e){
      var parentNode=e.target.parentNode;
      dojo.replaceClass(parentNode,"border_fat","border_thin");
      query('> div.removeFile',parentNode).style('display','block').onclick(function(){
         widget._removeFiles(query('input[type="hidden"]', this)[0].value);
      });
   });
   query("> div", this._divFilesPost).onmouseout(function(e){
      var parentNode=e.target.parentNode;
      dojo.replaceClass(parentNode,"border_thin","border_fat");
      query('> div.removeFile',parentNode).style('display','none');
   });
}
});});}
